home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / keymap.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2009-10-31  |  3.6 KB  |  143 lines

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:             keymap
  4. # Required-Start:       mountdevsubfs
  5. # Required-Stop:     
  6. # Default-Start:        S
  7. # Default-Stop:
  8. # X-Interactive:    true
  9. # Short-Description:     Set keymap
  10. # Description:        Set the Console keymap
  11. ### END INIT INFO
  12.  
  13. # If setupcon is present, then we've been superseded by console-setup.
  14. if type setupcon >/dev/null 2>&1; then
  15.     exit 0
  16. fi
  17.  
  18. . /lib/lsb/init-functions
  19.  
  20. # Avoid messing with splashy boot
  21. # Thanks to John Hughes and Marc Haber for suggestions
  22. pidof splashy >/dev/null &&
  23.    mkdir -p /lib/init/rw/splashy/ &&
  24.    touch /lib/init/rw/splashy/splashy-stopped-keymap &&
  25.    exit 0
  26.  
  27. #
  28. # Load the keymaps *as soon as possible*
  29. #
  30.  
  31. # Don't fail on error
  32. CONSOLE_TYPE=`fgconsole 2>/dev/null` || CONSOLE_TYPE="unknown"
  33.  
  34. # Don't fail on serial consoles
  35.  
  36. QUIT=0
  37. # fail silently if loadkeys not present (yet).
  38. command -v loadkeys >/dev/null 2>&1 || QUIT=1
  39.  
  40. CONFDIR=/etc/console
  41. CONFFILEROOT=boottime
  42. EXT=kmap
  43. CONFFILE=${CONFDIR}/${CONFFILEROOT}.${EXT}.gz
  44.  
  45. reset_kernel()
  46. {
  47.     # On Mac PPC machines, we may need to set kernel vars first
  48.         # We need to mount /proc to do that; not optimal, as its going to 
  49.         # be mounted in S10checkroot, but we need it set up before sulogin
  50.         # may be run in checkroot, which will need the keyboard to log in...
  51.     [ -x /sbin/sysctl ] || return
  52.     [ -r /etc/sysctl.conf ] || return
  53.     grep -v '^\#' /etc/sysctl.conf | grep -q keycodes 
  54.     if [ "$?" = "0" ] ; then
  55.         grep keycodes /etc/sysctl.conf | grep -v "^#" | while read d ; do
  56.             /sbin/sysctl -w $d 2> /dev/null || true
  57.             done
  58.         fi
  59. }
  60.  
  61. unicode_start_stop()
  62. {
  63.     # Switch unicode mode by checking the locale.
  64.     # This will be needed before loading the keymap.
  65.     [ -x /usr/bin/unicode_start ] || [ -x /bin/unicode_start ] ||  return
  66.     [ -x /usr/bin/unicode_stop ] || [ -x /bin/unicode_stop ] || return
  67.  
  68.     ENV_FILE=""
  69.     [ -r /etc/environment ] && ENV_FILE="/etc/environment"
  70.     [ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale" 
  71.     [ "$ENV_FILE" ] && CHARMAP=$(set -a && . "$ENV_FILE" && locale charmap)
  72.     if [ "$CHARMAP" = "UTF-8" ]; then
  73.         unicode_start 2> /dev/null || true
  74.     else
  75.         unicode_stop 2> /dev/null || true
  76.     fi
  77. }
  78.  
  79. if [ ! $QUIT = '1' ] ; then
  80.  
  81.   case "$1" in
  82.       start | restart | force-reload | reload)
  83.   
  84.           # Set kernel variables if required
  85.      reset_kernel
  86.  
  87.         # First mount /proc if necessary...and if it is there (#392798)
  88.         unmount_proc="no"
  89.     if [ -d /proc ]; then
  90.             if [ ! -x /proc/$$ ]; then
  91.                 unmount_proc="yes"    
  92.                  mount -n /proc
  93.             fi
  94.   
  95.  
  96.             if [ -f /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes ] ; then
  97.                 linux_keycodes=`cat /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes`
  98.         else
  99.                 linux_keycodes=1;
  100.             fi
  101.     else
  102.                linux_keycodes=1;
  103.     fi
  104.  
  105.     # load new map
  106.     if [ $linux_keycodes -gt 0 ] ; then 
  107.       if [ -r ${CONFFILE} ] ; then
  108.  
  109.         # Switch console mode to UTF-8 or ASCII as necessary
  110.         unicode_start_stop
  111.  
  112.         if [ $CONSOLE_TYPE = "serial" ] ; then 
  113.             loadkeys -q ${CONFFILE} 2>&1 > /dev/null
  114.         else
  115.                 loadkeys -q ${CONFFILE}
  116.         fi
  117.         if [ $? -gt 0 ]
  118.         then
  119.             # if we've a serial console, we may not have a keyboard, so don't
  120.         # complain if we fail. 
  121.            if [ ! $CONSOLE_TYPE = "serial" ]; then 
  122.             log_warning_msg "Problem when loading ${CONFDIR}/${CONFFILEROOT}.${EXT}.gz, use install-keymap"
  123.             sleep 10
  124.            fi 
  125.         fi
  126.         fi
  127.     fi
  128.  
  129.     # unmount /proc if we mounted it
  130.         [ "$unmount_proc" = "no" ] || umount -n /proc
  131.  
  132.     ;;
  133.  
  134.     stop)
  135.     ;;
  136.  
  137.     *)
  138.     log_warning_msg "Usage: $0 {start|stop|restart|reload|force-reload}"
  139.     ;;
  140.   esac
  141.  
  142. fi
  143.